<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var str = "hello world";
    str = "hello javascript";
    console.log(str.length);
    console.log(str[str.length - 1]);
    for(var i = 0; i < str.length; i++){
        // console.log(str[i]);   //依次打印str的字符
        console.log(str.charAt(i));
    }
    //父字符串.indexof（子字符串）
    //在父字符串中查找子字符串出现的位置
    //如果查找到了匹配的字符串，返回子字符串出现的
    //索引位置；如果差找不到则返回-1

    var result = str.indexOf("world");
    console.log("出现索引的位置：" + result);

    var result = str.indexOf("hello");
    console.log("出现索引的位置：" + result);
</script>
</html>